package wyn.spec.edu;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

public class MessageAdapter extends ArrayAdapter<Message> {
    private int itemLayoutId;
    public MessageAdapter(Context context, int textViewResourceId, @NonNull List<Message> objects){
        super(context,textViewResourceId,objects);
        itemLayoutId=textViewResourceId;
    }
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        // 取当前操作的数据项, position表示objects（list）里面的某一个位置
        Message f = getItem(position);
        // 根据模板构造空的View，这个时候还没有图片和文字，只有空的框架
        View view = LayoutInflater.from(getContext()).inflate(itemLayoutId, parent, false);
        NetImageView iv = (NetImageView)view.findViewById(R.id.image);
        TextView name = (TextView)view.findViewById(R.id.title);
        TextView textView=(TextView)view. findViewById(R.id.text);
        iv.setImageURL("http://www.yyjsx.xyz" + f.getPreview());
        name.setText(f.getTitle());
        textView.setText(f.getContext());
        return view;
    }
}
